﻿using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace DFGK_WMS.WebAPI.Controllers.Inventory
{
    /// <summary>
    /// 库存管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class InventoryController : ControllerBase
    {

        private readonly ISqlSugarClient _Client;

        public InventoryController(ISqlSugarClient client)
        {
            _Client = client;
        }

        /// <summary>
        /// 根据物料id获取库存仓位
        /// </summary>
        /// <param name="materialId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GenInvenCellByMatId/{materialId}")]
        public IActionResult GenInventoryCellByMatId(int materialId)
        {

            var list = _Client.Queryable<TInventory>()
                .Where(x => x.MaterialId == materialId)
                .Select(t => new
                {
                    FromWarehouseId=t.WarehouseId,
                    FromWarehouseCode=t.WarehouseCode,
                    FromWarehouseName=t.WarehouseName,   
                    FromAreaId=t.AreaId,
                    FromAreaCode=t.AreaCode,
                    FromAreaName=t.AreaName, 
                    FromLocationId = t.LocationId,
                    FromLocationName = t.LocationName,
                    FromLocationCode = t.LocationCode
                })
                .ToList();

            return new JsonResult(BaseResult.Result(list, "200"));
        }

    }
}
